package org.smartopen.unionpay.openapi.service.impl;

import org.smartframework.unionpay.domain.SmartPayConfig;
import org.smartframework.unionpay.domain.request.SmartPayBaseRequest;
import org.smartframework.unionpay.domain.request.SmartPayRefundRequest;
import org.smartframework.unionpay.domain.request.SmartPayUnifiedorderRequest;
import org.smartframework.unionpay.properties.SmartUnionPayProperties;
import org.smartframework.unionpay.service.IPayChannelService;
import org.smartframework.unionpay.service.IPayOrderService;
import org.smartframework.unionpay.service.IRefundOrderService;
import org.smartframework.unionpay.service.impl.SmartUnionPayServiceImpl;
import org.springframework.stereotype.Service;

@Service
public class SmartUnionPay2ServiceImpl extends SmartUnionPayServiceImpl {

    public SmartUnionPay2ServiceImpl(IPayChannelService payChannelService, IPayOrderService payOrderService, IRefundOrderService refundOrderService, SmartUnionPayProperties payProperties) {
        super(payChannelService, payOrderService, refundOrderService, payProperties);
    }

    @Override
    public void requestBefore(SmartPayBaseRequest request, SmartPayConfig payConfig, SmartUnionPayProperties payProperties) {
        if (request instanceof SmartPayUnifiedorderRequest) {
            ((SmartPayUnifiedorderRequest) request).setNotifyUrl(super.replaceChannelId(payProperties.getNotifyUrl(), payConfig.getChannelId()));
        } else if (request instanceof SmartPayRefundRequest) {
            ((SmartPayRefundRequest) request).setNotifyUrl(super.replaceChannelId(payProperties.getRefundNotifyUrl(),payConfig.getChannelId()));
        }
    }
}
